{extend name="base:base-add" /}
{block name="style"}
<link rel="stylesheet" href="__LIB__/webuploader/0.1.5/webuploader.css">
{/block}
{block name="title"}
<title>添加文件</title>
{/block}
{block name="form"}
<form class="form form-horizontal" id="form-article-add">
    <div class="row clearfix">
        <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>上级分类：</label>
        <div class="form-controls col-xs-8 col-sm-4">
                <span class="select-box">
                    <select class="select" size="1" name="parent_id">
                        {empty name="category"}
                        <option value="0">顶级</option>
                        {else /}
                         <option value="0">顶级</option>
                        {volist name="category" id="vo"}
                        <option value="{$vo.id}">{$vo.name}</option>
                        {/volist}
                        {/empty}
                    </select>
                </span>
        </div>
    </div>
    <div class="row clearfix">
        <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>分类名：</label>
        <div class="form-controls col-xs-8 col-sm-4">
            <input type="text" class="input-text" value="" placeholder="" id="name" name="name">
        </div>
    </div>

    <div class="row clearfix">
        <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
            <button class="btn btn-secondary radius add" type="button"><i class="Hui-iconfont">&#xe632;</i>
                保存
            </button>
        </div>
    </div>
</form>
{/block}
{block name="script"}
<script type="text/javascript" src="__LIB__/webuploader/0.1.5/webuploader.js"></script>
<script type="text/javascript" src="__LIB__/datatables/1.10.15/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="__LIB__/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="__ADMIN__/business/js/main.js"></script>
<script type="text/javascript">
    $(".add").click(function () {
        $('.btn').attr('disabled', 'disabled')
        var postData = {};
        var data = $("form").serializeArray();
        $.each(data, function () {
            postData[this.name] = this.value
        });
        $.ajax({
            url: "{:url(\'attachment_category\')}",
            type: "post",
            data: postData,
            success: function (result) {
                var msgData = JSON.parse(result);
                if (msgData.status === true) {
                    layer.msg(msgData.message, {icon: 1, time: 1000}, function () {
                        var index = parent.layer.getFrameIndex(window.name)
                        parent.layer.close(index);
                    })
                } else {
                    layer.msg(msgData.message, {icon: 5, time: 2000})
                }
            },
        }, JSON);
    });
</script>
{/block}